package com.shujia.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo08Cartesian {
  def main(args: Array[String]): Unit = {
    /**
     * cartesian：转换算子
     * 可以对两份数据做笛卡尔积
     */

    val conf: SparkConf = new SparkConf()
    conf.setMaster("local")
    conf.setAppName("Demo08Cartesian")

    val sc: SparkContext = new SparkContext(conf)

    val intList: List[Int] = List[Int](1, 2, 3, 4, 5)
    val strList: List[String] = List[String]("a","b","c")

    val intRDD: RDD[Int] = sc.parallelize(intList)
    val strRDD: RDD[String] = sc.parallelize(strList)

    val cartesianRDD: RDD[(Int, String)] = intRDD.cartesian(strRDD)
    cartesianRDD.foreach(println)

  }

}
